package list;
import java.util.ArrayList;
import java.util.Random;

public class TestDemo4 {

    public static ArrayList<ArrayList<Integer>> yanghui(int line){
        ArrayList<ArrayList<Integer>> lists = new ArrayList<>();
        ArrayList<Integer> row1 = new ArrayList<>();
        row1.add(1);
        lists.add(row1);
        for (int i = 1; i < line; i++) {
            ArrayList<Integer> list = new ArrayList<>();
            list.add(1);
            for (int j = 1; j < i; j++) {
                list.add(lists.get(i-1).get(j-1)+lists.get(i-1).get(j));
            }
            list.add(1);
            lists.add(list);
        }
        return lists;
    }
    public static void main2(String[] args) {
        ArrayList<ArrayList<Integer>> lists = yanghui(6);
        for (int i = 0; i < lists.size(); i++) {
            System.out.println(lists.get(i));
        }
    }


    private static final String[] SUITS = {"♥","♦","♣","♠"};
    public static ArrayList<Card> buyCard(){
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = SUITS[i];
                int rank = j;
                cards.add(new Card(rank,suit));
            }
        }
        return cards;
    }
    private static void wash(ArrayList<Card> cards){
        Random random = new Random();
        for (int i = 0; i < 1000; i++) {
            swap(cards,random.nextInt(52),random.nextInt(52));
        }
    }
    private static void swap(ArrayList<Card> cards,int i,int j){
        Card temp = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,temp);
    }
    private static ArrayList<ArrayList<Card>> take(ArrayList<Card> cards,int number){
        ArrayList<Card> list1 = new ArrayList<>();
        ArrayList<Card> list2 = new ArrayList<>();
        ArrayList<Card> list3 = new ArrayList<>();
        ArrayList<ArrayList<Card>> lists = new ArrayList<>();
        lists.add(list1);
        lists.add(list2);
        lists.add(list3);
        while (true){
            int j = 0;
            for (; j < number; j++) {
                if (cards.size() > 0){
                    lists.get(j).add(cards.remove(0));
                }else{
                    return lists;
                }
            }
        }
    }
    public static void main(String[] args) {
        ArrayList<Card> cards = buyCard();
        System.out.println(cards);
        wash(cards);
        System.out.println(cards);
        ArrayList<ArrayList<Card>> lists = take(cards,3);
        System.out.println("==================");
        System.out.println(lists.get(0));
        System.out.println(lists.get(1));
        System.out.println(lists.get(2));
    }
}
class Card{
    private int rank;// 数字
    private String suit;// 花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return suit + " " + rank;
    }

}